package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/registry"
	"github.com/micro/go-micro/util/log"
	"github.com/micro/go-micro/web"
	"github.com/micro/go-plugins/registry/consul"
	user_medreams_com "go-micro-client/interface"
)

func main() {

	newRegistry := consul.NewRegistry(registry.Addrs("106.12.7.53:8500"))

	engine := gin.Default()

	webService := web.NewService(
		web.Registry(newRegistry),
		web.Name("api_client"),
		web.Handler(engine),
	)
	webService.Init()
	// New Service
	service := micro.NewService(
		micro.Name("go.micro.api.go"),
		micro.Version("latest"),
		micro.Registry(newRegistry),
	)

	service.Init()

	userService := user_medreams_com.NewUserService("go.micro.srv.go", service.Client())

	// Initialise service
	//service.Init(
	//	// create wrap for the Go srv client
	//)

	engine.Group("/")
	{
		engine.GET("/login", func(context *gin.Context) {
			var requestData user_medreams_com.LoginRequest
			err := context.Bind(&requestData)
			if err != nil {
				fmt.Println(err)
			}
			res, err := userService.Login(context, &requestData)
			context.JSON(200, res)
			fmt.Println(err)
		})
	}

	// Register Handler

	// Run service
	if err := webService.Run(); err != nil {
		log.Fatal(err)
	}
}
